package com.example.juc.until;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class jiafaCyclicBarrier {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,() -> {
            System.out.println("召唤神龙");
        });

        for (int i = 1; i <=7 ; i++) {
            final int num =i;
             new Thread(() ->{
                 System.out.println(Thread.currentThread().getName());
                 try {
                     cyclicBarrier.await(); //等待
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 } catch (BrokenBarrierException e) {
                     e.printStackTrace();
                 }
             },num+"").start();
        }
    }
}
